<template>
  <div class="index">
    <HeadView>
      <span slot="center">首页</span>
      <span slot="right"><i class="el-icon-search"></i></span>
    </HeadView>
    <!-- 轮播图 -->
    <div class="block">
      <el-carousel height="150px">
        <el-carousel-item v-for="(item, index) in data.imgList" :key="index">
          <h3 class="small">
            <img :src="require('@/assets/img/' + item.img)" alt="" />
          </h3>
        </el-carousel-item>
      </el-carousel>
    </div>
    <!-- banner部分 -->
    <div class="banner">
      <div
        class="b"
        v-for="(item, index) in data.ban"
        :key="index"
        @click="classify"
      >
        <img :src="require('@/assets/img/' + item.img)" alt="" />
        <p>{{ item.tit }}</p>
      </div>
    </div>
    <div class="nn">
      <div class="s-nav">
        <router-link to="/index/hot">热门推荐</router-link>
        <router-link to="/index/new">发现新品</router-link>
        <router-link to="/index/goods">所有商品</router-link>
      </div>
      <router-view></router-view>
    </div>
    <nav-view></nav-view>
  </div>
</template>
<script>
import HeadView from "@/components/HeadView.vue";
import NavView from "../components/NavView.vue";
import data from "../assets/json/data.json";

export default {
  data() {
    return {
      data,
    };
  },
  methods: {
    classify() {
      this.$router.push("/two");
    },
  },
  components: {
    NavView,
    HeadView,
  },
};
</script>
<style lang="scss" scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}
.small {
  width: 100%;
  height: 150px;
  img {
    width: 100%;
    height: 100%;
  }
}
.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
// 变成小圆点  vue穿透>>>
::v-deep .el-carousel__indicator--horizontal .el-carousel__button {
  width: 10px;
  height: 10px;
  background: transparent;
  border: 1px solid #ffffff;
  border-radius: 50%;
  opacity: 0.5;
}
::v-deep .el-carousel__indicator--horizontal.is-active .el-carousel__button {
  width: 10px;
  height: 10px;
  background: #ffffff;
  border-radius: 50%;
  opacity: 1;
}
.banner {
  display: flex;
  justify-content: space-around;
  align-items: center;
}
.b {
  background: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 10px;
  img {
    width: 80%;
  }
}
// 二级导航部分
// .nn {
//   padding: 10px;
// }
.s-nav {
  width: 94%;
  margin: 0 auto;
  height: 40px;
  line-height: 40px;
  border: 1px solid red;
  display: flex;
  justify-content: space-between;
  text-align: center;
  a {
    flex: 1;
    border-left: 1px solid red;
    text-decoration: none;
    color: red;
    font-size: 18px;
    &:nth-child(1) {
      border-left: 0;
    }
    &.router-link-active {
      background: red;
      color: #fff;
    }
  }
}
</style>
